package cn.tedu.yushouge.pet.adopt.controller;

import cn.tedu.yushouge.commons.pojo.vo.PageData;
import cn.tedu.yushouge.commons.web.JsonResult;
import cn.tedu.yushouge.pet.adopt.mapper.AdoptRecordMapper;
import cn.tedu.yushouge.pet.adopt.pojo.vo.AdoptListItemVO;
import cn.tedu.yushouge.pet.adopt.pojo.vo.AdoptListVO;
import cn.tedu.yushouge.pet.adopt.pojo.vo.AdoptRecordListVO;
import cn.tedu.yushouge.pet.adopt.service.IAdoptRecordService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "04. 宠物领养记录模块")
@RequestMapping("/adopt-record/")
@Slf4j
@Validated
public class AdoptRecordController {

    @Autowired
    IAdoptRecordService service;

    @GetMapping("list")
    @ApiOperation("查询宠物领养记录")
    @ApiOperationSupport(order = 420)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query")
    })
    public JsonResult<PageData<AdoptRecordListVO>> list(@Range(min = 1, message = "查询宠物失败，请提供正确的页码值！") Integer pageNum) {
        log.debug("开始处理【查询宠物领养列表申请】的请求，页码：{}", pageNum);
        if (pageNum == null || pageNum < 1) {
            pageNum = 1;
        }
        PageData<AdoptRecordListVO> pageData = service.list(pageNum);
        return JsonResult.ok(pageData);
    }

}
